# Load required packages
library(sf)
library(tidycensus)
library(tigris)
library(dplyr)
library(ggplot2)
library(units)
library(stringr)
library(knitr)
library(scales)
library(readr)
library(kableExtra)
# Load spatial data
pa_counties=st_read("/Users/cathy/GitHub/MUSA-5080-Fall-2025/lectures/week-04/data/Pennsylvania_County_Boundaries.shp")Reading layer `Pennsylvania_County_Boundaries' from data source
`/Users/cathy/GitHub/MUSA-5080-Fall-2025/lectures/week-04/data/Pennsylvania_County_Boundaries.shp'
using driver `ESRI Shapefile'
Simple feature collection with 67 features and 19 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -8963377 ymin: 4825316 xmax: -8314404 ymax: 5201413
Projected CRS: WGS 84 / Pseudo-Mercator
pa_hospital=st_read("/Users/cathy/GitHub/MUSA-5080-Fall-2025/lectures/week-04/data/hospitals.geojson")Reading layer `hospitals' from data source
`/Users/cathy/GitHub/MUSA-5080-Fall-2025/lectures/week-04/data/hospitals.geojson'
using driver `GeoJSON'
Simple feature collection with 223 features and 11 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -80.49621 ymin: 39.75163 xmax: -74.86704 ymax: 42.13403
Geodetic CRS: WGS 84
census_tracts <- tracts(state="PA", cb=TRUE)
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======== | 11%
|
|========= | 12%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|=========================== | 38%
|
|============================ | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
# Check that all data loaded correctly
head(pa_counties)Simple feature collection with 6 features and 19 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -8905670 ymin: 4862594 xmax: -8317930 ymax: 5161279
Projected CRS: WGS 84 / Pseudo-Mercator
OBJECTID MSLINK COUNTY_NAM COUNTY_NUM FIPS_COUNT COUNTY_ARE COUNTY_PER
1 336 46 MONTGOMERY 46 091 <NA> <NA>
2 337 8 BRADFORD 08 015 <NA> <NA>
3 338 9 BUCKS 09 017 <NA> <NA>
4 339 58 TIOGA 58 117 <NA> <NA>
5 340 59 UNION 59 119 <NA> <NA>
6 341 60 VENANGO 60 121 <NA> <NA>
NUMERIC_LA COUNTY_N_1 AREA_SQ_MI SOUND SPREAD_SHE IMAGE_NAME NOTE_FILE VIDEO
1 5 46 487.4271 <NA> <NA> poll.bmp <NA> <NA>
2 2 8 1161.3379 <NA> <NA> poll.bmp <NA> <NA>
3 5 9 622.0836 <NA> <NA> poll.bmp <NA> <NA>
4 2 58 1137.2480 <NA> <NA> poll.bmp <NA> <NA>
5 2 59 319.1893 <NA> <NA> poll.bmp <NA> <NA>
6 3 60 683.3676 <NA> <NA> poll.bmp <NA> <NA>
DISTRICT_N PA_CTY_COD MAINT_CTY_ DISTRICT_O geometry
1 06 46 4 6-4 MULTIPOLYGON (((-8398884 48...
2 03 08 9 3-9 MULTIPOLYGON (((-8558633 51...
3 06 09 1 6-1 MULTIPOLYGON (((-8367360 49...
4 03 59 7 3-7 MULTIPOLYGON (((-8558633 51...
5 03 60 8 3-8 MULTIPOLYGON (((-8562865 49...
6 01 61 5 1-5 MULTIPOLYGON (((-8870781 50...
head(pa_hospital)Simple feature collection with 6 features and 11 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -80.27907 ymin: 39.80913 xmax: -75.17005 ymax: 40.24273
Geodetic CRS: WGS 84
CHIEF_EXEC CHIEF_EX_1
1 Peter J Adamo President
2 Autumn DeShields Chief Executive Officer
3 Shawn Parekh Chief Executive Officer
4 DIANE HRITZ Chief Executive Officer
5 Tim Harclerode Chief Executive Officer
6 Richard McLaughlin MD MBA Chief Executive Officer
FACILITY_U LONGITUDE COUNTY
1 https://www.phhealthcare.org -79.91131 Washington
2 https://www.malvernbh.com -75.17005 Philadelphia
3 https://roxboroughmemorial.com -75.20963 Philadelphia
4 https://www.ashospital.net -80.27907 Washington
5 https://www.conemaugh.org -79.02513 Somerset
6 https://towerhealth.org -75.61213 Montgomery
FACILITY_N STREET
1 Penn Highlands Mon Valley 1163 Country Club Road
2 MALVERN BEHAVIORAL HEALTH 1930 South Broad Street Unit 4
3 Roxborough Memorial Hospital 5800 Ridge Avenue
4 ADVANCED SURGICAL HOSPITAL 100 TRICH DRIVE\nSUITE 1
5 DLP Conemaugh Meyersdale Medical Center 200 Hospital Drive
6 Pottstown Hospital, LLC 1600 East High Street
CITY_OR_BO LATITUDE TELEPHONE_ ZIP_CODE geometry
1 Monongahela 40.18193 724-258-1000 15063 POINT (-79.91131 40.18193)
2 Philadelphia 39.92619 610-480-8919 19145 POINT (-75.17005 39.9262)
3 Philadelphia 40.02869 215-483-9900 19128 POINT (-75.20963 40.02869)
4 WASHINGTON 40.15655 7248840710 15301 POINT (-80.27907 40.15655)
5 Meyersdale 39.80913 814-634-5911 15552 POINT (-79.02513 39.80913)
6 Pottstown 40.24273 6103277000 19464 POINT (-75.61213 40.24273)
head(census_tracts)Simple feature collection with 6 features and 13 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -78.42478 ymin: 39.79351 xmax: -75.93766 ymax: 40.54328
Geodetic CRS: NAD83
STATEFP COUNTYFP TRACTCE GEOIDFQ GEOID NAME
1 42 001 031101 1400000US42001031101 42001031101 311.01
2 42 013 100400 1400000US42013100400 42013100400 1004
3 42 013 100500 1400000US42013100500 42013100500 1005
4 42 013 100800 1400000US42013100800 42013100800 1008
5 42 013 101900 1400000US42013101900 42013101900 1019
6 42 011 011200 1400000US42011011200 42011011200 112
NAMELSAD STUSPS NAMELSADCO STATE_NAME LSAD ALAND AWATER
1 Census Tract 311.01 PA Adams County Pennsylvania CT 3043185 0
2 Census Tract 1004 PA Blair County Pennsylvania CT 993724 0
3 Census Tract 1005 PA Blair County Pennsylvania CT 1130204 0
4 Census Tract 1008 PA Blair County Pennsylvania CT 996553 0
5 Census Tract 1019 PA Blair County Pennsylvania CT 573726 0
6 Census Tract 112 PA Berks County Pennsylvania CT 1539365 9308
geometry
1 MULTIPOLYGON (((-77.03108 3...
2 MULTIPOLYGON (((-78.42478 4...
3 MULTIPOLYGON (((-78.41661 4...
4 MULTIPOLYGON (((-78.41067 4...
5 MULTIPOLYGON (((-78.40836 4...
6 MULTIPOLYGON (((-75.95433 4...